package model

import (
	"time"

	"gorm.io/gorm"
)

// Department 部门模型
type Department struct {
	ID        uint           `json:"id" gorm:"primarykey"`
	Name      string         `json:"name" gorm:"type:varchar(50);not null;comment:部门名称"`
	ParentID  uint           `json:"parent_id" gorm:"default:0;comment:父部门ID"`
	Sort      int            `json:"sort" gorm:"default:0;comment:排序"`
	Status    int            `json:"status" gorm:"default:1;comment:状态:1正常,2禁用"`
	Remark    string         `json:"remark" gorm:"type:varchar(255);comment:备注"`
	CreatedAt time.Time      `json:"created_at"`
	UpdatedAt time.Time      `json:"updated_at"`
	DeletedAt gorm.DeletedAt `json:"-" gorm:"index"`
	// 关联
	Users []User `gorm:"many2many:go_user_dept;" json:"users,omitempty"`
}

// TableName 指定表名
func (Department) TableName() string {
	return "go_department"
}

// DepartmentSearchParams 部门搜索参数
type DepartmentSearchParams struct {
	Name   string `json:"name" form:"name"`
	Status int    `json:"status" form:"status"`
}

// CreateDepartmentRequest 创建部门请求
type CreateDepartmentRequest struct {
	Name     string `json:"name" binding:"required"`
	ParentID uint   `json:"parent_id"`
	Sort     int    `json:"sort" binding:"required"`
	Status   int    `json:"status" binding:"required"`
	Remark   string `json:"remark"`
}

// UpdateDepartmentRequest 更新部门请求
type UpdateDepartmentRequest struct {
	Name     string `json:"name" binding:"required"`
	ParentID uint   `json:"parent_id"`
	Sort     int    `json:"sort" binding:"required"`
	Status   int    `json:"status" binding:"required"`
	Remark   string `json:"remark"`
}
